<?php
namespace app\oa\controller;
use \app\oa\controller\Role as RoleController;
use app\oa\ext\Role;
use app\oa\model\Task;

/**
 * 秘书
 * Class Secretary
 * @package app\oa\controller
 */
class Secretary extends RoleController {

    protected function getRole()
    {
        return [Role::Secretary, Role::DeputySecretary];
    }

    public function index() {
        $tasks = Task::all(['status'=>4]);
        $this->assign("tasks", $tasks);
        $sendTasks = Task::all(['status'=>6]);
        $this->assign("sendTasks", $sendTasks);
        return $this->fetch("secretary/index");
    }

    public function accept($id) {
        $task = Task::get($id);
        switch ($task['status']) {
            case 4:
                $task['status'] = 5;
                break;
            case 6:
                $task['status'] = 7;
                break;
        }

        if($task->save()) {
            $this->success("操作成功");
        }else{
            $this->error("操作失败");
        }
    }

}